import { ref, onMounted, onUnmounted } from 'vue'

export function useMouse() {
  let x = ref(0)
  let y = ref(0)

  function move() {
    let pageX = window.event.pageX
    let pageY = window.event.pageY

    x.value = pageX
    y.value = pageY
  }

  onMounted(() => {
    window.addEventListener('mousemove', move)
  })

  onUnmounted(() => {
    window.removeEventListener('mousemove', move)
  })

  return { x, y }
}
